package de.zainodis.authorlist.ui;

import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.os.Bundle;
import de.zainodis.authorlist.R;

/**
 * This {@link Activity} is shown, when the application is first launched.
 * 
 * @author zainodis
 * 
 */
public class MainActivity extends Activity {

   private static final String SELETED_TAB_INDEX = "tabIndex";

   @Override
   protected void onCreate(Bundle savedInstanceState) {
	 super.onCreate(savedInstanceState);

	 // Setup the action bar
	 ActionBar actionBar = getActionBar();

	 // Show the navigation bar
	 actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

	 // Add the products tab
	 Tab tab = actionBar
		  .newTab()
		  .setText(getString(R.string.products))
		  .setTabListener(
			   new NavigationTabListener<AuthorListFragment>(this, AuthorListFragment.TAG,
				    AuthorListFragment.class));
	 actionBar.addTab(tab);

	 // Add the about tab
	 tab = actionBar
		  .newTab()
		  .setText(getString(R.string.about))
		  .setTabListener(
			   new NavigationTabListener<AboutFragment>(this, AboutFragment.TAG,
				    AboutFragment.class));
	 actionBar.addTab(tab);

	 
	 if (savedInstanceState != null) {
	    int index = savedInstanceState.getInt(SELETED_TAB_INDEX);
	    actionBar.setSelectedNavigationItem(index);
	 }
   }

   
      @Override
   protected void onSaveInstanceState(Bundle outState) {
	 super.onSaveInstanceState(outState);
	 outState.putInt(SELETED_TAB_INDEX, getSupportActionBar().getSelectedTab().getPosition());
   }

}
